import type { SwitchProps } from 'element-plus'

type UseElSwitchProps<
  D extends Record<string, any>,
  P extends keyof Readonly<D>
> = UseFormItemProps<SwitchProps, D, P>

/**
 * el-switch
 * @param prop item.prop
 * @param label item.label
 * @param props item的其他属性
 * @returns form-item-data
 */
export function useElSwitch<
  T extends Record<string, any>,
  P extends keyof T
>(prop: P, label: string, props: UseElSwitchProps<T, P> = {}) {
  return {
    prop,
    label,
    ...props,
    component: 'el-switch'
  }
}

/**
 * el-switch 启用/禁用
 * @param prop item.prop
 * @param label item.label
 * @param props item的其他属性
 * @returns form-item-data
 */
export function useElSwitchStatus<
  T extends Record<string, any>,
  P extends keyof T
>(prop: P, label: string, props: UseElSwitchProps<T, P> = {}) {
  if (!props.props) {
    props.props = {}
  }

  props.props.activeValue = props.props.activeText = '启用'
  props.props.inactiveValue = props.props.inactiveText = '禁用'

  return {
    prop,
    label,
    ...props,
    component: 'el-switch'
  }
}
